<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图形验证码</title>

</head>
<body>


<a href="http://localhost:9001/easyCaptcha/get">
    获取Easy图形验证码
</a>
<a href="http://localhost:9001/kaptcha/get">
    获取kaptcha图形验证码
</a>
<hr>
<div id="div1"></div>


<script type="text/javascript">
    window.onload = function () {
        var aNodes = document.getElementsByTagName('a');
        for (var i = 0; i < aNodes.length; i++) {
            aNodes[i].onclick = function () {

                var xmlHttp = new XMLHttpRequest();

                var method = "GET";
                var url = this.href + "?time=" + new Date();

                xmlHttp.open(method, url);

                xmlHttp.send(null);

                xmlHttp.onreadystatechange = function () {
                    if (xmlHttp.readyState == 4) {
                        if (xmlHttp.status == 200) {
                            var jsonObject = xmlHttp.responseText;//用responseText
                            var jsonText = eval("(" + jsonObject + ")");//转换为json对象
                            var name = jsonText.data.imgBase64;
                            var div1 = document.getElementById('div1');
                            div1.innerHTML="" ;

                            var img = document.createElement("img");
                            img.src = "data:image/gif;base64," + name;

                            div1.appendChild(img);

                        }
                    }
                }
                return false;
            }
        }

    }
</script>


</body>


</html>